import 'dart:convert';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:panda/base/Constant.dart';
import 'package:panda/base/SignType.dart';
import 'package:panda/base/application.dart';
import 'package:panda/http/Api.dart';
import 'package:panda/http/HttpUtil.dart';
import 'package:panda/set/TuiGuangMingXi.dart';
import 'package:panda/util/AppSaveInfoUtil.dart';
import 'package:panda/util/SignUtil.dart';

import 'DrawMoney.dart';

class TuiGuangShouYiPage extends StatefulWidget {
  TuiGuangShouYiPage({Key key}) : super(key: key);

  @override
  _TuiGuangShouYiPageState createState() => _TuiGuangShouYiPageState();
}

class _TuiGuangShouYiPageState extends State<TuiGuangShouYiPage> {
  String token = "",phone="";
  String balance = "0",
      exchange_money = "0",
      extend_money = "0",
      today_price = "0",
      today_total = "0",
      yes_price = "0",
      yes_total = "0";
  String month_price = "0",
      month_total = "0",
      last_month_price = "0",
      last_month_total = "0";
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getString(TOKEN).then((value) {
      token = value;
      getData();
    });
    phone=APPLIC.userInfoMap['user_msg']['phone'];
  }

  getData() async {
    Map map = new Map();
    map['token'] = token;
    map['sign_type'] = SignType.GET_GOODSPROFIT;
    Response<String> response =
        await HttpUtil().post(Api.GET_GOODSPROFIT, data: getSign(map));
    Map userMap = json.decode(response.data);
    if (userMap['code'] != 1) {
      Fluttertoast.showToast(msg: userMap['msg']);
      return;
    }
    // AddressListEntity homeListEntity = new AddressListEntity.fromJson(userMap);
    if (mounted)
      setState(() {
        balance = userMap['data']['balance'].toString();
        exchange_money = userMap['data']['exchange_money'].toString();
        extend_money = userMap['data']['extend_money'].toString();
        today_price = userMap['data']['today']['price'].toString();
        today_total = userMap['data']['today']['total'].toString();
        yes_price = userMap['data']['yesterday']['price'].toString();
        yes_total = userMap['data']['yesterday']['total'].toString();
        month_price = userMap['data']['month']['price'].toString();
        month_total = userMap['data']['month']['total'].toString();
        last_month_price = userMap['data']['last_month']['price'].toString();
        last_month_total = userMap['data']['last_month']['total'].toString();
      });
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      // appBar: AppBar(
      //   title: Text(
      //     '团队分红',
      //     style: TextStyle(color: black, fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
      //   ),
      //   elevation: 0.2,
      //   backgroundColor: white,
      //   iconTheme: new IconThemeData(color: black_99),
      //   brightness: Brightness.light,
      // ),
      body: Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
          Widget>[
             Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil.getInstance().setHeight(DP_20),
                 ScreenUtil.getInstance().setHeight(DP_20),
                ScreenUtil.getInstance().setHeight(DP_20),
                ScreenUtil.getInstance().setHeight(0)),
            color: white,
            padding: EdgeInsets.fromLTRB(
                ScreenUtil.getInstance().setHeight(0),
                20,
                ScreenUtil.getInstance().setHeight(DP_30),
                ScreenUtil.getInstance().setHeight(DP_30)),
            child: Row(children: <Widget>[
              Expanded(
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        '累计分红(元)',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE-2)),
                      ),
                      Container(height: 8),
                      Text(
                        '$extend_money',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE)),
                      ),
                    ]),
              ),
              Expanded(
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        '已使用(元)',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE-2)),
                      ),
                      Container(height: 8),
                      Text(
                        '$exchange_money',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE)),
                      ),
                    ]),
              ),
              Expanded(
                child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Text(
                        '可使用(元)',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE-2)),
                      ),
                      Container(height: 8),
                      Text(
                        '$balance',
                        style: TextStyle(
                            color: Colors.black87,
                            fontSize: ScreenUtil.getInstance()
                                .setSp(NORMAL_FONT_SIZE)),
                      ),
                    ]),
              ),
            ])),
        Container(
            margin: EdgeInsets.fromLTRB(
                ScreenUtil.getInstance().setHeight(DP_20),
               0,
                ScreenUtil.getInstance().setHeight(DP_20),
               ScreenUtil.getInstance().setHeight(DP_20)),
            color: white,
            padding: EdgeInsets.only(left:ScreenUtil.getInstance().setHeight(DP_30),bottom:ScreenUtil.getInstance().setHeight(DP_30)),
            child: Row(children: <Widget>[
              Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      '账户余额',
                      style: TextStyle(
                          color: black,
                          fontSize:
                              ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE-2)),
                    ),
                    Container(height: 8),
                    Text(
                      '$balance',
                      style: TextStyle(
                          color: mainColor,
                          fontSize:
                              ScreenUtil.getInstance().setSp(BIG_FONT_SIZE)),
                    ),
                    // Container(height: 8),
                    // Text(
                    //   '立即推广,立享分红',
                    //   style: TextStyle(
                    //       color: Colors.black54,
                    //       fontSize: ScreenUtil.getInstance()
                    //           .setSp(NINIEST_FONT_SIZE + 2)),
                    // ),
                  ]),
              Container(
                width: DP_80,
              ),
              Offstage(
                child:GestureDetector(
                child: Container(
                  alignment: Alignment.center,
                  height: ScreenUtil.getInstance().setHeight(DP_50),
                  padding: EdgeInsets.only(left: 20, right: 20),
                  decoration: BoxDecoration(
                    border: Border.all(color: mainColor, width: 1),
                    borderRadius: BorderRadius.circular(
                        ScreenUtil.getInstance().setHeight(DP_50)),
                  ),
                  child: Text('立即申请',
                      style: TextStyle(
                          color: mainColor,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE))),
                ),
                onTap: () {
                  Navigator.of(context)
                      .push(new MaterialPageRoute(builder: (context) {
                    return new DrawMoneyPage(
                      total: balance,
                    );
                  }));
                },
                behavior: HitTestBehavior.opaque,
              ),
              offstage: phone=='15161177235',
              )
            ])),
        // Padding(
        //   padding: EdgeInsets.only(left: 20, bottom: 20),
        //   child: Text(
        //     '日分红',
        //     style: TextStyle(
        //         color: Colors.black87,
        //         fontSize: ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
        //   ),
        // ),
        // Stack(children: <Widget>[
        //   Container(
        //     margin: EdgeInsets.fromLTRB(
        //         ScreenUtil.getInstance().setHeight(DP_20),
        //         0,
        //         ScreenUtil.getInstance().setHeight(DP_20),
        //         ScreenUtil.getInstance().setHeight(DP_20)),
        //     color: white,
        //     padding: EdgeInsets.fromLTRB(
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30)),
        //     child: Row(children: <Widget>[
        //       Expanded(
        //         child: Column(
        //             crossAxisAlignment: CrossAxisAlignment.center,
        //             children: <Widget>[
        //               Text(
        //                 '付款笔数',
        //                 style: TextStyle(
        //                     color: Colors.black54,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(SMALL_FONT_SIZE)),
        //               ),
        //               Container(height: 8),
        //               Text(
        //                 '$today_total',
        //                 style: TextStyle(
        //                     color: Colors.black87,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(NORMAL_FONT_SIZE)),
        //               ),
        //             ]),
        //       ),
        //       Expanded(
        //         child: Column(
        //             crossAxisAlignment: CrossAxisAlignment.center,
        //             children: <Widget>[
        //               Text(
        //                 '付款结算收入',
        //                 style: TextStyle(
        //                     color: Colors.black54,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(SMALL_FONT_SIZE)),
        //               ),
        //               Container(height: 8),
        //               Text(
        //                 '$today_price',
        //                 style: TextStyle(
        //                     color: Colors.black87,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(NORMAL_FONT_SIZE)),
        //               ),
        //             ]),
        //       ),
        //     ]),
        //   ),
        //   Positioned(
        //       left: 15,
        //       child: Container(
        //         padding: EdgeInsets.all(3),
        //         color: Colors.orange,
        //         child: Text(
        //           '今',
        //           style: TextStyle(
        //               color: white,
        //               fontSize: ScreenUtil.getInstance().setSp(MINI_FONT_SIZE)),
        //         ),
        //       ))
        // ]),
        // Stack(children: <Widget>[
        //   Container(
        //     margin: EdgeInsets.fromLTRB(
        //         ScreenUtil.getInstance().setHeight(DP_20),
        //         0,
        //         ScreenUtil.getInstance().setHeight(DP_20),
        //         ScreenUtil.getInstance().setHeight(DP_20)),
        //     color: white,
        //     padding: EdgeInsets.fromLTRB(
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30),
        //         ScreenUtil.getInstance().setHeight(DP_30)),
        //     child: Row(children: <Widget>[
        //       Expanded(
        //         child: Column(
        //             crossAxisAlignment: CrossAxisAlignment.center,
        //             children: <Widget>[
        //               Text(
        //                 '付款笔数',
        //                 style: TextStyle(
        //                     color: Colors.black54,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(SMALL_FONT_SIZE)),
        //               ),
        //               Container(height: 8),
        //               Text(
        //                 '$yes_total',
        //                 style: TextStyle(
        //                     color: Colors.black87,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(NORMAL_FONT_SIZE)),
        //               ),
        //             ]),
        //       ),
        //       Expanded(
        //         child: Column(
        //             crossAxisAlignment: CrossAxisAlignment.center,
        //             children: <Widget>[
        //               Text(
        //                 '付款结算收入',
        //                 style: TextStyle(
        //                     color: Colors.black54,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(SMALL_FONT_SIZE)),
        //               ),
        //               Container(height: 8),
        //               Text(
        //                 '$yes_price',
        //                 style: TextStyle(
        //                     color: Colors.black87,
        //                     fontSize: ScreenUtil.getInstance()
        //                         .setSp(NORMAL_FONT_SIZE)),
        //               ),
        //             ]),
        //       ),
        //     ]),
        //   ),
        //   Positioned(
        //       left: 15,
        //       child: Container(
        //         padding: EdgeInsets.all(3),
        //         color: Colors.orange,
        //         child: Text(
        //           '昨',
        //           style: TextStyle(
        //               color: white,
        //               fontSize: ScreenUtil.getInstance().setSp(MINI_FONT_SIZE)),
        //         ),
        //       ))
        // ]),
        Padding(
          padding: EdgeInsets.only(left: 20, bottom: 20),
          child: Text(
            '月分红',
            style: TextStyle(
                color: Colors.black87,
                fontSize: ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
          ),
        ),
        Container(
          margin: EdgeInsets.fromLTRB(
              ScreenUtil.getInstance().setHeight(DP_20),
              0,
              ScreenUtil.getInstance().setHeight(DP_20),
              ScreenUtil.getInstance().setHeight(0)),
          color: white,
          padding: EdgeInsets.fromLTRB(
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30)),
          child: Row(children: <Widget>[
            Expanded(
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      '本月付款笔数',
                      style: TextStyle(
                          color: Colors.black54,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE)),
                    ),
                    Container(height: 8),
                    Text(
                      '$month_total',
                      style: TextStyle(
                          color: Colors.black87,
                          fontSize:
                              ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
                    ),
                  ]),
            ),
            Expanded(
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      '本月结算收入',
                      style: TextStyle(
                          color: Colors.black54,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE)),
                    ),
                    Container(height: 8),
                    Text(
                      '$month_price',
                      style: TextStyle(
                          color: Colors.black87,
                          fontSize:
                              ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
                    ),
                  ]),
            ),
          ]),
        ),
        Container(
          margin: EdgeInsets.fromLTRB(
              ScreenUtil.getInstance().setHeight(DP_20),
              0,
              ScreenUtil.getInstance().setHeight(DP_20),
              ScreenUtil.getInstance().setHeight(DP_20)),
          color: white,
          padding: EdgeInsets.fromLTRB(
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30),
              ScreenUtil.getInstance().setHeight(DP_30)),
          child: Row(children: <Widget>[
            Expanded(
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      '上月付款笔数',
                      style: TextStyle(
                          color: Colors.black54,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE)),
                    ),
                    Container(height: 8),
                    Text(
                      '$last_month_total',
                      style: TextStyle(
                          color: Colors.black87,
                          fontSize:
                              ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
                    ),
                  ]),
            ),
            Expanded(
              child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    Text(
                      '上月结算收入',
                      style: TextStyle(
                          color: Colors.black54,
                          fontSize:
                              ScreenUtil.getInstance().setSp(SMALL_FONT_SIZE)),
                    ),
                    Container(height: 8),
                    Text(
                      '$last_month_price',
                      style: TextStyle(
                          color: Colors.black87,
                          fontSize:
                              ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
                    ),
                  ]),
            ),
          ]),
        ),
        Expanded(
          child: Center(),
        ),
        // GestureDetector(
        //     onTap: () {
        //       Navigator.of(context).push(MaterialPageRoute(builder: (context) {
        //         return new TuiGuangMingXiPage();
        //       }));
        //     },
        //     child: Container(
        //       color: white,
        //       padding: EdgeInsets.all(20),
        //       child: Row(children: <Widget>[
        //         Expanded(
        //           child: Text(
        //             '账单明细',
        //             style: TextStyle(
        //                 color: Colors.black87,
        //                 fontSize:
        //                     ScreenUtil.getInstance().setSp(NORMAL_FONT_SIZE)),
        //           ),
        //         ),
        //         Icon(Icons.arrow_forward_ios, size: 20, color: Colors.black54)
        //       ]),
        //     ))
      ]),
    );
  }
}
